package com.jlnk.stockdemo.utils;

import android.graphics.Bitmap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ImageUtils {

    /**
     * 将Bitmap转换为JPG文件
     *
     * @param bitmap 要转换的Bitmap对象
     * @param outputPath 输出文件的路径
     * @param quality JPEG图片的质量，取值范围是0（最差）到100（最佳）
     * @return 返回生成的JPG文件对象
     */
    public static File convertBitmapToJPG(Bitmap bitmap, String outputPath, int quality) {
        File outputFile = new File(outputPath);
        try {
            FileOutputStream out = new FileOutputStream(outputFile);
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return outputFile;
    }
}